<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>三目运算符</title>
  <script src="https://cdn.bootcss.com/react/16.4.0/umd/react.development.js"></script>
  <script src="https://cdn.bootcss.com/react-dom/16.4.0/umd/react-dom.development.js"></script>
  <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
</head>

<body>
  <div id="root">

  </div>
</body>

</html>

<script type="text/babel">

class Welcome extends React.Component {
   constructor(props) {
       super(props);
   }

   render() {
       /**
       * 通过变量isLogin来决定显示什么内容
       * 使用三目运算符(内容较短用三目运算符)
       * 再长一点用上面if else的方式
       * 更长的内容封装成一个组件更合适
       */
      return (
        this.props.isLogin?
        <h1>欢迎回来, <button style={{color: 'blue'}}>退出登录</button></h1>:
         <h1>你还没登录, <button  style={{color: 'red'}}>请登录</button></h1>
      )
   }

}

ReactDOM.render(
   <Welcome isLogin={true}/>,
   document.getElementById('root')
)


</script>
